//package com.cqie.interceptor;
//
//import com.auth0.jwt.exceptions.AlgorithmMismatchException;
//import com.auth0.jwt.exceptions.SignatureVerificationException;
//import com.auth0.jwt.exceptions.TokenExpiredException;
//import com.cqie.util.JwtTokenUtil;
//
//import com.cqie.util.ResultTemplate;
//import com.fasterxml.jackson.databind.ObjectMapper;
//import jakarta.servlet.http.HttpServletRequest;
//import jakarta.servlet.http.HttpServletResponse;
//import org.slf4j.Logger;
//import org.slf4j.LoggerFactory;
//import org.springframework.web.servlet.HandlerInterceptor;
//
//
//
//public class JWTInterceptor implements HandlerInterceptor {
//    private Logger logger = LoggerFactory.getLogger(getClass());
//
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
//        String token = request.getHeader("token");
//        String msg;
//        try{
//            JwtTokenUtil.verify(token);
//            return true;
//        }catch (SignatureVerificationException e){
//            msg = "签名无效";
//        }catch (TokenExpiredException e){
//            msg = "签名过期";
//        }catch (AlgorithmMismatchException e){
//            msg = "签名不一致";
//        }catch (Exception e){
//            msg = "token无效";
//        }
//
//        String error = new ObjectMapper().writeValueAsString(ResultTemplate.Failed(msg));
//        response.setContentType("application/json;charset = utf-8");
//        response.getWriter().println(error);
//        return false;
//    }
//}